import {
    debounce
} from '@/common/utils'

let pageScrollFn = (() => {
    let pageScrollTop = 0;
    return function(e) {
        this.rollDirection = pageScrollTop <= e.scrollTop ? 'up' : 'down';
        pageScrollTop = e.scrollTop;
        uni.$emit('pageScroll', {
            ...e,
            direction: this.rollDirection
        })
    }
})();

export default {
    data() {
        return {
            rollDirection: 'up',
            shareParams: {
                imageUrl: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/share-logo@3.png',
                title: '中装速配',
                path: 'pages/home/home',//点击链接进入的页面
                webUrl: 'http://uniapp.dcloud.io'//兼容低版本的网页链接
            }
        }
    },
    // #ifdef MP-WEIXIN
    //微信小程序分享，其他端分享文件@/mixins/share.js
    onShareAppMessage() {
        let {
            title = '中装速配',
            path = 'pages/home/home'
        } = this.shareParams || {};
        return {
            title: title,
            path: path
        }
    },
    // #endif
    onPageScroll(e) {
        let that = this;
        debounce(function pageScrollDebounce() {
            pageScrollFn.call(that, e)
        }, 1000 / 60)
    }
}
